package cn.jinjimi.app.custom.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.jinjimi.base.util.DateUtils;
import cn.jinjimi.app.R;
import cn.jinjimi.app.custom.entity.Proposal;
import cn.jinjimi.app.interfaces.DataSetChangeListener;
import cn.jinjimi.app.main.adapter.extend.MyBaseAdapter;
import cn.jinjimi.app.main.widget.FrescoImageView.FrescoImageView;

/**
 * Created by Roy
 * Date: 17/1/11
 */

public class ProposalListAdapter extends MyBaseAdapter<Proposal> {
    private Context mContext;

    private DataSetChangeListener dataSetChangeListener;

    public ProposalListAdapter(Context context, DataSetChangeListener listener) {
        this.mContext = context;

        this.dataSetChangeListener = listener;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
        if (dataSetChangeListener != null)
            dataSetChangeListener.dataChange();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;

        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_insure_follow_plan_list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Proposal item = getItem(position);

        holder.img.setPlaceHolderImage(R.drawable.list_icon_project);
        holder.tvName.setText(item.name);
        holder.tvSendTime.setText(String.format(mContext.getString(R.string.customer_proposal_sent_time), DateUtils.formatYYYYMMDD(item.sendTime)));

        return convertView;
    }

    public class ViewHolder {
        public FrescoImageView img;

        public RelativeLayout cardView;
        public TextView tvName;
        public TextView tvSendTime;
        public TextView tvContent;

        public ViewHolder(View view) {
            img = (FrescoImageView) view.findViewById(R.id.img);

            cardView = (RelativeLayout) view.findViewById(R.id.card_view);
            tvName = (TextView) view.findViewById(R.id.tv_title);
            tvSendTime = (TextView) view.findViewById(R.id.tv_sec_title);
            tvContent = (TextView) view.findViewById(R.id.tv_third_title);
            tvContent.setVisibility(View.GONE);
        }
    }
}
